package com.qifan.alb2b.action.back;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qifan.alb2b.domain.PictureInfoDomain;
import com.qifan.alb2b.service.PictureInfoService;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.ID;
import com.qifan.alb2b.util.Page;

@Controller
@RequestMapping("/admin/picture")
public class PictureManageController{
	private PictureInfoService pictureInfoService;

	
	
	public void setPictureInfoService(PictureInfoService pictureInfoService) {
		this.pictureInfoService = pictureInfoService;
	}

	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm,PictureInfoDomain uqp) {
		//spring太给力了，可以自动装配两个对象  会自动的装返回的Map转换成JSON对象
		return pictureInfoService.query(dgm,uqp);
	}
	
	@RequestMapping("/add.adm")
	@ResponseBody
	public Map<String, Object> add(PictureInfoDomain pictureInfoDomain){
		Map<String, Object> map=new HashMap<String, Object>();
		pictureInfoDomain.setPictureId(ID.next()+"");
		pictureInfoDomain.setCreateTime(new Date());
		pictureInfoService.add(pictureInfoDomain);
		map.put("success", true);
		return map;
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(PictureInfoDomain pictureInfoDomain){
		
		Map<String, Object> map=new HashMap<String, Object>();
		pictureInfoDomain.setCreateTime(new Date());
		pictureInfoService.update(pictureInfoDomain);
		map.put("success", true);	
		return map;
	}
	
	@RequestMapping("/del.adm")
	@ResponseBody
	public Map<String, Object> delete(@RequestParam("uid") String[] ids){
		Map<String, Object> map=new HashMap<String, Object>();
		pictureInfoService.delete(ids);
		map.put("success", true);
		return map;
	}
	
}
